package com.example.mapper;

import com.example.dto.ReportListDto;
import com.example.pojo.Cidetailedreport;
import com.example.pojo.Cireport;
import com.example.pojo.Overallresult;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ReportMapper {
    //查询体检报告
    @Select("SELECT o.orderId, o.orderDate, h.name " +
            "FROM orders o " +
            "LEFT JOIN hospital h ON o.hpId = h.hpId" +
            " WHERE userId = #{userId}")
    List<ReportListDto> getOrdersWithHospitalNames(@Param("userId") String userId);

    @Select("SELECT * FROM cireport WHERE orderId = #{orderId} ")
    List<Cireport> selectCireportByOrderId(@Param("orderId") Integer orderId);

    @Select("SELECT  DISTINCT " +
            " c.ciId,c.ciName,c.orderId," +
            " cdr.name,cdr.unit,cdr.minrange,cdr.maxrange,cdr.normalValue," +
            " cdr.normalValueString,cdr.type,cdr.value,cdr.isError" +
            " FROM cidetailedreport cdr " +
            " JOIN cireport c ON c.ciId = cdr.ciId AND c.orderId = cdr.orderId " +
            " WHERE cdr.orderId = #{orderId} ")
    List<Cidetailedreport> selectCidetailedreportByOrderId(@Param("orderId") Integer orderId);

    @Select("SELECT * FROM overallresult WHERE orderId = #{orderId} ")
    List<Overallresult> selectOverallresultByOrderId(@Param("orderId") Integer orderId);



}
